<?php
/* @var $this BController */
/* @var $app CWebApplication */
/* @var $cs CClientScript */

$app = Yii::app();
$cs = $app->getClientScript();
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('cookie');

$this->pageTitle = '文件浏览';
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="<?php echo $app->charset; ?>">
	<title><?php echo CHtml::encode($this->pageTitle); ?></title>
	<link rel="stylesheet" href="<?php echo $this->baseUrl; ?>/css/dashicons/css/dashicons.css">
	<link rel="stylesheet" href="<?php echo $this->baseUrl; ?>/css/style.css">
	<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>
<style>
	.file .file-icon {
		float: left;
		width: 100px;
		text-align: center;
		border: 1px solid #ccc;
		margin-right: 20px;
		background: #fff;
		height: 100px;
		line-height: 100px;
	}
	.file-icon img {
		max-width: 100px;
		max-height: 100px;
	}
	.file {
		clear: both;
		overflow: hidden;
		*zoom: 1;
		padding: 10px;
		background: #fff;
		border: 1px solid #ccc;
		box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
		margin-bottom:  10px;
	}

	.file-meta {
		float: left;
		margin: 10px 20px 0 0;
	}

	.file-select {
		float: left;
		margin: 20px 20px 0;
	}

	.file-meta label {
		display: inline-block;
		margin-right: 10px;;
	}
	.file-meta label input {
		vertical-align: top;
	}
</style>
<body>
<div class="container-fluid file-browse">
<h2>文件浏览</h2>

	<?php
	/** @var TbActiveForm $form */
	$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
		'type' => 'inline',
		'method' => 'get',
	)); ?>
	<?php
	echo $form->searchFieldRow($model, 'name');
	 $this->widget('bootstrap.widgets.TbButton', array(
		'buttonType' => 'submit',
		'type' => 'primary',
		'encodeLabel' => false,
		'label' => '搜索'
	)); ?>

	<?php $this->endWidget(); ?>
<?php
/** @var CActiveDataProvider $dataProvider */
$dataProvider = $model->search();
$this->widget('bootstrap.widgets.TbListView', array(
	'dataProvider' => $dataProvider,
	'itemView' => '_file',
	'sortableAttributes' => array('create_time'),
))
?>
</body>
</html>
<?php
if (isset($_GET['CKEditorFuncNum'])) {
$js = <<<EOT
var funcNum = {$_GET['CKEditorFuncNum']};
$('.post-select').click(function() {
	var url;
	var checked = $('input[name=size]:checked');
	if (checked.length > 0)
		fileUrl = checked.val();
	else
		fileUrl = $(this).data('url');

	if (window.opener.CKEDITOR)
		window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl);

	window.close();
});
EOT;
} elseif (isset($_GET['input'])) {
$input = $_GET['input'];
$js = <<<EOT
$('.post-select').click(function() {
	var url;
	var checked = $('input[name=size]:checked');
	if (checked.length > 0)
		fileUrl = checked.val();
	else
		fileUrl = $(this).data('url');

	if (window.opener)
		window.opener.jQuery("#{$input}").val(fileUrl);

	window.close();
});
EOT;
}
Yii::app()->getClientScript()->registerScript(__CLASS__ .'#'. $this->getId(), $js);
?>
